package core.vols;

import java.util.ArrayList;

import core.ClasseVol;

import time.Heure;
import map.Airport;

public class Vol implements Comparable<Vol>{
	
	protected Airport depart;
	protected Airport arrivee;
	protected Heure heureDepart;
	protected Heure duree;
	protected Heure heureArrivee;
	protected VolFret volFret;
	protected VolCommercial volCommercial;
	protected Boolean isFret;
	protected Boolean isCommercial;
	protected String code;
	protected double distance;
	protected Prix prixBase;
	
	/**
	 * @param depart
	 * @param arrivee
	 * @param heureDepart
	 * @param duree
	 * @param volFret
	 * @param volCommercial
	 */
	public Vol(String code, Airport depart, Airport arrivee, Heure heureDepart, Heure duree, VolFret volFret, VolCommercial volCommercial) {
		super();
		this.depart = depart;
		this.arrivee = arrivee;
		this.heureDepart = heureDepart;
		this.duree = duree;
		this.volFret = volFret;
		this.volCommercial = volCommercial;
		this.isCommercial=true;
		this.isFret=true;
		this.code=code;
		distance = (depart.getCoord().distance(arrivee.getCoord()));
		prixBase = new Prix(50);
		heureArrivee = new Heure(heureDepart);
		heureArrivee.addDuree(duree);
	}
	
	/**
	 * @param depart
	 * @param arrivee
	 * @param heureDepart
	 * @param duree
	 * @param volFret
	 */
	public Vol(String code, Airport depart, Airport arrivee, Heure heureDepart, Heure duree, VolFret volFret) {
		super();
		this.depart = depart;
		this.arrivee = arrivee;
		this.heureDepart = heureDepart;
		this.duree = duree;
		this.volFret = volFret;
		this.isCommercial=false;
		this.isFret=true;
		this.code=code;
		distance = (depart.getCoord().distance(arrivee.getCoord()));
		prixBase = new Prix(50);
		heureArrivee = new Heure(heureDepart);
		heureArrivee.addDuree(duree);
	}
	
	/**
	 * @param depart
	 * @param arrivee
	 * @param heureDepart
	 * @param duree
	 * @param volCommercial
	 */
	public Vol(String code, Airport depart, Airport arrivee, Heure heureDepart, Heure duree, VolCommercial volCommercial) {
		super();
		this.depart = depart;
		this.arrivee = arrivee;
		this.heureDepart = heureDepart;
		this.duree = duree;
		this.volCommercial = volCommercial;
		this.isCommercial=true;
		this.isFret=false;
		this.code=code;
		distance = (depart.getCoord().distance(arrivee.getCoord()));
		prixBase = new Prix(50);
		heureArrivee = new Heure(heureDepart);
		heureArrivee.addDuree(duree);
	}
	
	protected Vol(Vol v) {
		super();
		this.depart = v.depart;
		this.arrivee = v.arrivee;
		this.heureDepart = v.heureDepart;
		this.duree = v.duree;
		this.code = v.code;
		if(v.isFret) {
			this.volFret = v.volFret;
			this.isFret=true;
		} 
		if(v.isCommercial) {
			this.volCommercial = v.volCommercial;
			this.isCommercial=true;	
		}
		distance = (depart.getCoord().distance(arrivee.getCoord()));
		prixBase = new Prix(50);
		heureArrivee = new Heure(heureDepart);
		heureArrivee.addDuree(duree);
	}

	/**
	 * @return the volFret
	 */
	public VolFret getVolFret() {
		return volFret;
	}

	/**
	 * @return the volCommercial
	 */
	public VolCommercial getVolCommercial() {
		return volCommercial;
	}

	/**
	 * @return the isFret
	 */
	public Boolean getIsFret() {
		return isFret;
	}

	/**
	 * @return the isCommercial
	 */
	public Boolean getIsCommercial() {
		return isCommercial;
	}

	public Heure getHeureDepart() {
		return heureDepart;
	}
	
	
	
	public Heure getHeureArrivee() {
		return heureArrivee;
	}

	public String toString() {
		return "Vol "+ code + " "+ depart + " (" + heureDepart + ") to " + arrivee  + " (" + heureArrivee + ")";  
	}

	public String getCode() {
		return code;
	}


	public Airport getDepart() {
		return depart;
	}

	public Airport getArrivee() {
		return arrivee;
	}

	public double getDistance() {
		return distance;
	}

	/**
	 * @return the prixBaseEco
	 */
	public Prix getPrixBase(ClasseVol classe) {
		switch(classe) {
		case ECO:
			return new Prix(prixBase.getPrix());
		case AFFAIRE:
			return new Prix(prixBase.getPrix()+50);
		case C1:
			return new Prix(prixBase.getPrix()+80);
		default:
			return new Prix(prixBase.getPrix());
		}
	}
	
	
	public Heure getDuree() {
		return duree;
	}

	@Override
	public int compareTo(Vol o) {
		return this.heureDepart.compareTo(((Vol)o).heureDepart);
	}
	
	

}
